<?php
include_once("checkAdmin.php");
?>
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>会员管理系统</title>
    <style>
        .main {
            width: 80%;
            margin: 0 auto;
            text-align: center;
            /* background: green; */
        }

        a{
            text-decoration: none;
            color: black;
        }
        a:hover{
            text-decoration: underline;
            color: brown;
        }

    </style>
</head>
<body>
<div class="main">
    <?php
    include_once "nav.php";
    include_once "conn.php";
    include_once "page.php";
    $sql = "select count(id) as total from user";
    $result = mysqli_query($conn, $sql);
    $total = mysqli_fetch_array($result)['total']; // 得到记录总数
    $perPage = 2; // 设置每一页显示多少条数据
    $page = $_GET["page"] ?? 1; // 读取当前页码
    paging($total, $perPage); // 引用分页函数
    $sql = "select id,username,email,sex,fav,admin from user order by id asc limit $firstCount, $displayPG";
    $result = mysqli_query($conn, $sql);
    ?>
    <table border="1" cellspacing="0" cellpadding="10" style="border-collapse: collapse;" align="center" width="90%">
        <tr>
            <th>id</th>
            <th>username</th>
            <th>email</th>
            <th>sex</th>
            <th>fav</th>
            <th>是否为管理员</th>
            <th>操作</th>
        </tr>
        <?php $i = $firstCount + 1;
        while ($info = mysqli_fetch_array($result)) { // 取出一条命令  ?>
            <tr>
                <td><?php echo $i ?></td>
                <td><?php echo $info['username']; ?></td>
                <td><?php echo $info['email']; ?></td>
                <td><?php echo $info['sex'] ? '男' : '女'; ?></td>
                <td><?php echo $info['fav']; ?></td>
                <td><?php echo $info['admin'] ? '是' : '否'; ?></td>
                <td>
                    <button class="delUser">删除会员</button>
                    <?php if (!$info['admin']) {
                        echo "<a href='setAdmin.php?action=1&id=" . $info['id'] . "'>设置管理员</a>";
                    }else{
                        echo "<a href='setAdmin.php?action=0&id=" . $info['id'] . "'>删除管理员</a>";
                    }
                    ?>


                </td>
            </tr>
            <?php $i++;
        } ?>
    </table>
    <?php
    echo $pageNav;
    ?>
</div>
</body>
</html>